from sqlalchemy import Column, ForeignKey, Date
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.oracle import VARCHAR2, NUMBER
from app.db.base import Base
from app.models.iaro_career.ite_survey_assigned import ITESurveyAssigned


# ITE Detail Entity

class ITEDetail(Base):
    __tablename__ = 'ITE_DETAIL'
    __table_args__ = {'schema': 'IARO_CAREER'}

    ite_id             = Column(NUMBER, primary_key=True)
    scholar_id         = Column(VARCHAR2(20), ForeignKey('IARO_CAREER.SCHOLARS.scholar_id'))
    sponsor_name       = Column(VARCHAR2(500))
    department         = Column(VARCHAR2(500))
    ite_number         = Column(NUMBER)
    prst_date          = Column(Date)
    ite_start          = Column(Date)
    ite_finish         = Column(Date)
    sponsor_evl_date   = Column(Date)
    completed_evl_date = Column(Date)
    completed_form_date= Column(Date)
    ite_detail_date    = Column(Date)
    ite_prst_date      = Column(Date)
    cocode             = Column(VARCHAR2(1000))

    # Relationships
    scholar            = relationship("Scholar", back_populates="ite_details")
    supervisors        = relationship("ITESupervisor", back_populates="detail")
    surveys_assigned   = relationship("ITESurveyAssigned", back_populates="detail")
    dashboard_manual = relationship("ITEDashboardManual", back_populates="ite_detail", uselist=False,
                                    cascade="all, delete-orphan")
